<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\User */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;

$this->title = '注册';
$this->params['breadcrumbs'][] = $this->title;
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />-->
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=0" />
    <title>注册</title>
    <?=Html::cssFile('@frontend/css/enroll.css')?>
    <?=Html::jsFile('@admin/js/area.js')?>
    <?=Html::jsFile('@api/js/jquery-2.1.0.js')?>
</head>
<body>
<header>
    <h1>注册</h1>
</header>
<section>
    <?php $form = ActiveForm::begin(['options'=>['onsubmit'=>'return sumbit_sure()']]); ?>
        <label>
            <input type="text" name="User[name]" id="" value="<?=$model->name?>" placeholder="请输入你的用户名" required="required"/>
        </label>
        <label>
            <input type="password" name="User[pwd]" id="" value="" placeholder="请输入你的密码"/>
        </label>
        <label>
            <input type="tel" name="User[tele]" id="tele" value="<?=$model->tele?>" placeholder="请输入你的手机号码" required="required"/>
        </label>
    <label>
        <select name="User[province]" id="province"></select>
        <select name="User[city]" id="city"></select>
        <select name="User[county]" id="county"></select>
    </label>

        <label>
            <input type="text" id="prov" value="" placeholder="请输入手机验证码"/>
            <a href="#" class="proving">获取验证码</a>
        </label>
        <input type="submit" value="确定" id="sub"/>
    <?php ActiveForm::end()?>
    <div class="xieyi">
        <p><label><input type="checkbox"><span></span></label>我已阅读并同意竞拍<a href="#">服务协议</a></p>
    </div>
</section>
</body>
<script type="text/javascript">
    var code = '';
    function sumbit_sure(){

        if(code == ''){
            alert("请获取验证码");
            return false
        }
        var register = $('#prov').val();
        if(register  != code) {
            alert("验证码不正确");
            return false
        }
        var subs=document.querySelector("input[type='checkbox']");
        var gnl=subs.checked;
        if (gnl==true){
            return true;
        }else{
            alert("请同意竞拍协议");
            console.log("请同意竞拍协议")
            return false;
        }
    }
    $('.proving').click(function(){
        var tele = $('#tele').val()
        if(tele.length == 0){
            alert("请填写电话")
        }else{
            $.post('<?=Url::to(['api/user/sendline'])?>',{tele:tele},function(res){
                console.log(res)
                if(res.status=="1")
                    code = res.data.register
            })
        }
    })
    _init_area()
    <?php if($model->hasErrors()):?>
        alert('<?=current($model->getFirstErrors())?>')
        console.log('<?=current($model->getFirstErrors())?>')
    <?php endif;?>
</script>
</html>
